package com.c6906.vdam.dcs.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.stereotype.Service;

@Service
public class DeviceLogService {
    // 需验证多线程有没有问题，如果有异常则使用字典来存储Logger对象，每个设备一个
    private static final Logger deviceLogger = LoggerFactory.getLogger("DEVICE");

    public void logDeviceData(String deviceId, String data) {
        try {
            MDC.put("deviceId", deviceId);// 设置设备ID到MDC
            deviceLogger.info("{}", data);// 记录设备日志
        } finally {
            MDC.remove("deviceId");// 确保清除MDC中的设备ID
        }
    }

}
